<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="GenerateSprintBacklog.aspx.cs" Inherits="CreateEditSprint" Title="Tackle - Generate Sprint Backlog" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="Server">
    <span style="font-family: Verdana"><span style="font-size: 10pt"><strong>Generate Sprint
        Backlog<br />
    </strong><span style="font-size: 8pt">
        <br />
        Follow the wizard below to generate a backlog for a sprint.<br />
        <br />
        <asp:UpdatePanel runat="server" ID="UPGridView" UpdateMode="Conditional" RenderMode="Block">
            <ContentTemplate>
                <asp:Wizard ID="wizGenerateSprintBacklog" runat="server" ActiveStepIndex="0" BackColor="#E6E2D8"
                    BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
                    Font-Size="X-Small" DisplayCancelButton="True" OnNextButtonClick="wizGenerateSprintBacklog_NextButtonClick"
                    OnFinishButtonClick="wizGenerateSprintBacklog_FinishButtonClick" CancelDestinationPageUrl="~/GenerateSprintBacklog.aspx"
                    CellPadding="5" DisplaySideBar="False">
                    <StepStyle BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="2px" />
                    <SideBarStyle BackColor="#1C5E55" Font-Size="0.9em" VerticalAlign="Top" />
                    <NavigationButtonStyle BackColor="White" BorderColor="#C5BBAF" BorderStyle="Solid"
                        BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#1C5E55" />
                    <WizardSteps>
                        <asp:WizardStep runat="server" AllowReturn="False" StepType="Start" Title="Select Sprint">
                            <span style="font-size: 8pt">Select the sprint to generate the backlog on: </span>
                            <asp:DropDownList ID="ddSprintSelection" runat="server" DataSourceID="dsGetSprintScheduleNames"
                                DataTextField="SprintName" DataValueField="MasterBacklogScheduleID" Font-Size="X-Small" OnPreRender="ddSprintSelection_PreRender">
                            </asp:DropDownList>
                        </asp:WizardStep>
                        <asp:WizardStep runat="server" Title="Sprint Resources" AllowReturn="False" StepType="Step">
                            <table width="100%">
                                <tr>
                                    <td style="width: 482px">
                                        <strong>Sprint:</strong>
                                        <asp:Label ID="lblSprintName" runat="server" Font-Names="Verdana" Font-Size="X-Small"></asp:Label>
                                        &nbsp;<br />
                                        <br />
                                        <asp:GridView ID="gvViewSprintResources" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                                            CellPadding="4" DataKeyNames="SprintResourcesID" DataSourceID="dsSprintResource"
                                            Font-Size="X-Small" ForeColor="#333333" GridLines="None" OnRowDeleting="gvViewSprintResources_RowDeleting"
                                            OnRowUpdating="gvViewSprintResources_RowUpdating" ShowFooter="True" Width="95%"
                                            OnPreRender="gvViewSprintResources_PreRender">
                                            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                                            <AlternatingRowStyle BackColor="White" />
                                            <EditRowStyle BackColor="#7C6F57" VerticalAlign="Top" />
                                            <Columns>
                                                <asp:BoundField DataField="SprintResourcesID" HeaderText="ID" InsertVisible="False"
                                                    ReadOnly="True" SortExpression="SprintResourcesID" Visible="False" />
                                                <asp:BoundField DataField="fSprintID" HeaderText="fSprintID" SortExpression="fSprintID"
                                                    Visible="False" />
                                                <asp:TemplateField HeaderText="Person" SortExpression="Person">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox1" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                            Text='<%# Bind("Person") %>' ToolTip="The person's alias that is a resource in the sprint"></asp:TextBox><asp:RequiredFieldValidator
                                                                ID="rfv1" runat="server" ControlToValidate="TextBox1" ErrorMessage="*?" ForeColor="LightCoral"
                                                                Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Person") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Buffer" SortExpression="Buffer">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="tbBuffer" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                            Text='<%# Bind("Buffer", "{0:F}") %>' ToolTip="The buffer for the resource for the sprint"
                                                            Width="30px" OnPreRender="NumberTextBox_PreRender"></asp:TextBox><asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="tbBuffer"
                                                                ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small"
                                                                ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                                    ID="rv2" runat="server" ControlToValidate="tbBuffer" ErrorMessage="*#" ForeColor="LightCoral"
                                                                    Font-Names="Verdana" Font-Size="Small" MaximumValue="10000" MinimumValue="0.01"
                                                                    ToolTip="This field must contain a number between 0.01 and 10000" Type="Double"></asp:RangeValidator>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Buffer", "{0:F}") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="OOF Hours" SortExpression="OOFHours">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="tbOOFHours" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                            Text='<%# Bind("OOFHours", "{0:F}") %>' ToolTip="The amount of OOF time for this resource in this sprint."
                                                            Width="50px" OnPreRender="NumberTextBox_PreRender"></asp:TextBox><asp:RequiredFieldValidator ID="rfv3" runat="server" ControlToValidate="tbOOFHours"
                                                                ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small"
                                                                ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                                    ID="rv3" runat="server" ControlToValidate="tbOOFHours" ErrorMessage="*#" ForeColor="LightCoral"
                                                                    Font-Names="Verdana" Font-Size="Small" MaximumValue="10000" MinimumValue="0"
                                                                    ToolTip="This field must contain a number between 0 and 10000" Type="Double"></asp:RangeValidator>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("OOFHours", "{0:F}") %>'></asp:Label>
                                                    </ItemTemplate>
                                                    <HeaderStyle Wrap="False" />
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Available Sprint Hours" SortExpression="Available Sprint Hours">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="tbAvSprintHours" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                            Text='<%# Bind("AvailableSprintHours", "{0:F}") %>' ToolTip="This value is calculated automatically if Calculate Sprint Hours is checked."
                                                            Width="50px" OnPreRender="NumberTextBox_PreRender"></asp:TextBox><asp:RequiredFieldValidator ID="rfv4" runat="server" ControlToValidate="tbAvSprintHours"
                                                                ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small"
                                                                ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                                    ID="rv4" runat="server" ControlToValidate="tbAvSprintHours" ErrorMessage="*#"
                                                                    ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small" MaximumValue="10000"
                                                                    MinimumValue="0" ToolTip="This field must contain a number between 0 and 10000"
                                                                    Type="Double"></asp:RangeValidator>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("AvailableSprintHours", "{0:F}") %>'></asp:Label>
                                                    </ItemTemplate>
                                                    <HeaderStyle Wrap="False" />
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Calculate Sprint Time" SortExpression="CalculateSprintHours">
                                                    <EditItemTemplate>
                                                        <asp:CheckBox ID="cbCalcSprintHours" runat="server" Checked='<%# Bind("CalculateSprintHours") %>'
                                                            ToolTip="If Calculate Sprint Hours is checked, the available sprint hours column is calculated automatically." />
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("CalculateSprintHours") %>'
                                                            Enabled="false" />
                                                    </ItemTemplate>
                                                    <HeaderStyle Wrap="False" />
                                                </asp:TemplateField>
                                                <asp:CommandField ShowEditButton="True" />
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="linkButtonDelete" runat="server" CommandName="Delete" ForeColor="Black"
                                                            OnClientClick="return confirm('Are you sure you want to delete this record?');">Delete</asp:LinkButton>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                            <RowStyle BackColor="#E3EAEB" />
                                            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                        </asp:GridView>
                                        <asp:SqlDataSource ID="dsSprintResource" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
                                            DeleteCommand="DELETE FROM tblSprintResources WHERE (SprintResourcesID = @original_SprintResourcesID)"
                                            InsertCommand="INSERT INTO tblSprintResources(fSprintID, Person, Buffer, OOFHours, CalculateSprintHours, AvailableSprintHours) VALUES (@SprintID,@Person,@Buffer,@OOFHours,@CalculateSprintHours,@AvailableSprintHours)"
                                            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT SprintResourcesID, fSprintID, Person, Buffer, OOFHours * @TimeMult as OOFHours, CalculateSprintHours, AvailableSprintHours * @TimeMult as AvailableSprintHours FROM tblSprintResources WHERE (fSprintID = @SprintID)
ORDER BY Person" UpdateCommand="UPDATE tblSprintResources SET Person = @Person, Buffer = @Buffer, OOFHours = @OOFHours, CalculateSprintHours = @CalculateSprintHours, AvailableSprintHours = @AvailableSprintHours WHERE (SprintResourcesID = @original_SprintResourcesID)"
                                            CancelSelectOnNullParameter="False">
                                            <InsertParameters>
                                                <asp:ControlParameter ControlID="ddSprintSelection" Name="SprintID" PropertyName="SelectedValue" />
                                                <asp:Parameter Name="Person" />
                                                <asp:Parameter Name="Buffer" />
                                                <asp:Parameter Name="OOFHours" />
                                                <asp:Parameter Name="CalculateSprintHours" />
                                                <asp:Parameter Name="AvailableSprintHours" />
                                            </InsertParameters>
                                            <SelectParameters>
                                                <asp:SessionParameter Name="SprintID" SessionField="GenerateSprintID" />
                                                <asp:SessionParameter Name="TimeMult" SessionField="SBTimeMult" />
                                            </SelectParameters>
                                            <UpdateParameters>
                                                <asp:Parameter Name="Person" />
                                                <asp:Parameter Name="Buffer" />
                                                <asp:Parameter Name="OOFHours" />
                                                <asp:Parameter Name="CalculateSprintHours" />
                                                <asp:Parameter Name="AvailableSprintHours" />
                                                <asp:Parameter Name="original_SprintResourcesID" />
                                            </UpdateParameters>
                                            <DeleteParameters>
                                                <asp:Parameter Name="original_SprintResourcesID" />
                                            </DeleteParameters>
                                        </asp:SqlDataSource>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 482px">
                                        <asp:Button ID="btnNewResource" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                            OnClick="btnNewResource_Click" Text="New Resource" />
                                        &nbsp;<asp:LinkButton ID="lkInsertResourcesFromLastSprint" runat="server" Font-Names="Verdana"
                                            Font-Size="X-Small" ForeColor="Black" OnClick="lkInsertResourcesFromLastSprint_Click"
                                            ToolTip="Inserts the resources that were active in the previous sprint calculating new available sprint hours based on this sprints length of time.">Insert Resources From Last Sprint</asp:LinkButton>
                                        <br />
                                        <asp:Label ID="lblNeedResources" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                            ForeColor="Red" Text="At least one resource must be defined before generating a sprint backlog."
                                            Visible="False"></asp:Label>
                                        <asp:Label ID="lblCantDelete" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                            ForeColor="Red" Text="The user cannot be deleted as associated sprint backlog items exists."
                                            Visible="False"></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </asp:WizardStep>
                        <asp:WizardStep runat="server" AllowReturn="False" StepType="Finish" Title="Select Backlog Items">
                            <strong>Sprint:</strong>
                            <asp:Label ID="lblSprintName2" runat="server" Font-Names="Verdana" Font-Size="X-Small"></asp:Label>
                            &nbsp;&nbsp;<br />
                            <br />
                            <asp:GridView ID="gvBacklogSelection" runat="server" CellPadding="4" ForeColor="#333333"
                                GridLines="None" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="dsBacklogSelection"
                                DataKeyNames="MasterBacklogID" OnPreRender="gvBacklogSelection_PreRender">
                                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                                <AlternatingRowStyle BackColor="White" VerticalAlign="Top" />
                                <EditRowStyle BackColor="#7C6F57" VerticalAlign="Top" />
                                <RowStyle BackColor="#E3EAEB" VerticalAlign="Top" />
                                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                <Columns>
                                    <asp:TemplateField HeaderText="Add to Sprint">
                                        <EditItemTemplate>
                                            <asp:CheckBox ID="CheckBox1" runat="server" />
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="CheckBox1" runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="MasterBacklogID" HeaderText="MasterBacklogID" InsertVisible="False"
                                        ReadOnly="True" SortExpression="MasterBacklogID" Visible="False" />
                                    <asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />
                                    <asp:BoundField DataField="Feature" HeaderText="Feature" SortExpression="Feature" />
                                    <asp:BoundField DataField="Activity" HeaderText="Activity" SortExpression="Activity" />
                                    <asp:TemplateField HeaderText="Description" SortExpression="Description">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblDescription" runat="server" OnPreRender="lblDescription_PreRender"
                                                Text='<%# Bind("Description") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="MasterRank" HeaderText="Master Rank" SortExpression="MasterRank" />
                                    <asp:TemplateField HeaderText="Time" SortExpression="Estimation">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Estimation") %>'></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Estimation", "{0:F}") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Accum. Time"></asp:TemplateField>
                                    <asp:TemplateField HeaderText="Sprint End"></asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            <asp:SqlDataSource ID="dsBacklogSelection" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
                                OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:TackleConnectionStringMain.ProviderName %>"
                                SelectCommand="SELECT tblProducts.ProductName, tblMasterBacklog.Feature, tblMasterBacklog.Activity, tblMasterBacklog.Description, tblMasterBacklog.MasterRank, tblMasterBacklog.Hours * @TimeMult AS Estimation, tblMasterBacklog.MasterBacklogID FROM tblMasterBacklog INNER JOIN tblProducts ON tblMasterBacklog.fProductID = tblProducts.ProductID INNER JOIN tblScrumTeam ON tblProducts.fScrumTeamProductListID = tblScrumTeam.ScrumTeamProductListID WHERE (tblMasterBacklog.FeatureComplete = 0) AND (tblScrumTeam.ScrumTeamID = @ScrumTeamID) AND (tblMasterBacklog.ShowInMB = 1) AND (tblProducts.ProductComplete = 0) ORDER BY tblMasterBacklog.MasterRank">
                                <SelectParameters>
                                    <asp:SessionParameter Name="ScrumTeamID" SessionField="ScrumTeamID" />
                                    <asp:SessionParameter Name="TimeMult" SessionField="MBTimeMult" />
                                </SelectParameters>
                            </asp:SqlDataSource>
                        </asp:WizardStep>
                    </WizardSteps>
                    <SideBarButtonStyle ForeColor="White" />
                    <HeaderStyle BackColor="#666666" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="2px"
                        Font-Bold="True" Font-Size="0.9em" ForeColor="White" HorizontalAlign="Center" />
                </asp:Wizard>
                <br />
                <asp:Label ID="lblNoSprintsDefined" runat="server" Font-Bold="False" Font-Italic="False"
                    ForeColor="Red" Text="Note: There are no sprints defined. Use the Scrum Schedule Entry to setup your sprint schedule."
                    Visible="False"></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
        <span style="font-size: 7pt"></span>&nbsp;&nbsp;<br />
        <asp:SqlDataSource ID="dsGetSprintScheduleNames" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
            SelectCommand="SELECT tblMasterBacklogSchedule.SprintName, tblMasterBacklogSchedule.MasterBacklogScheduleID FROM tblSprint LEFT OUTER JOIN tblSprintBacklog ON tblSprint.SprintID = tblSprintBacklog.fSprintID RIGHT OUTER JOIN tblMasterBacklogSchedule ON tblSprint.fMasterBacklogScheduleID = tblMasterBacklogSchedule.MasterBacklogScheduleID WHERE (tblMasterBacklogSchedule.fScrumTeamID = @ScrumTeamID) AND (tblSprintBacklog.fSprintID IS NULL) ORDER BY tblMasterBacklogSchedule.EndDate">
            <SelectParameters>
                <asp:SessionParameter Name="ScrumTeamID" SessionField="ScrumTeamID" />
            </SelectParameters>
        </asp:SqlDataSource>
    </span></span></span>
</asp:Content>
